Proactively check for NULL strings passed into xc_linx_build. Either do
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Tue, 10 Jan 2006 14:28:41 +0000 (15:28 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Tue, 10 Jan 2006 14:28:41 +0000 (15:28 +0100)
the right thing or return error if detected.  A NULL cmdline, for example,
would currently generate a segfault.

Signed-off-by: Ben Thomas <bjthomas3@gmail.com>
tools/libxc/xc_linux_build.c
tools/libxc/xg_private.c

index a48ecd45bdbd255379ed41810286fac4f13536c5..8d119717f255ca911985cc787bb53442178979bd 100644 (file)
@@ -693,8 +693,11 @@ static int setup_guest(int xc_handle,
         start_info->mod_start    = vinitrd_start;
         start_info->mod_len      = initrd_len;
     }
-    strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
-    start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
+    if ( cmdline != NULL )
+    {
+        strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
+        start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
+    }
     munmap(start_info, PAGE_SIZE);
 
     /* shared_info page starts its life empty. */
index 355ba1400df8928a1a34ce7b82f9a231702c4ded..982d8256be708507d8fc178a59832905c9ba4ca4 100644 (file)
@@ -17,6 +17,9 @@ char *xc_read_kernel_image(const char *filename, unsigned long *size)
     char *image = NULL;
     unsigned int bytes;
 
+    if ( filename == NULL )
+        goto out;
+
     if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
     {
         PERROR("Could not open kernel image");